package com.ego.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @Title
 * @Author Lyg
 * @Description:
 */
@Configuration
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
    @Bean
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        //设置登录信息
        http.formLogin()
                .loginPage("/")
                .loginProcessingUrl("/login")
                .successForwardUrl("/loginSuccession");
        //拦截url地址设置\
        http.authorizeRequests()
                .antMatchers("/css/**").permitAll()
                .antMatchers("/js/**").permitAll()
                .antMatchers("/").permitAll() //放行登录页面
                .anyRequest().authenticated();

        // 不要在响应头中添加X-Frame-Options: DENY
        http.headers().frameOptions().disable();


        //关闭csrf跨站请求伪造防护
        http.csrf().disable();
    }
}
